//
//  Horloge.m
//  Metronome
//
//  Created by Thomas Dupont on 29/09/09.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "Horloge.h"


@implementation Horloge

- (id)init
{
	if([super init] != nil)
	{
		lesTimers = [[NSMutableDictionary alloc] init];
	}
	return self;
}

- (void)activerCommande:(id<CommandProtocol>)uneCommande periodiquement:(float)unePeriode
{
	[lesTimers setObject:[[NSTimer scheduledTimerWithTimeInterval:unePeriode target:uneCommande selector:@selector(execute) userInfo:nil repeats:YES] retain] 
				  forKey:[uneCommande getName]];
}

- (void)activerCommande:(id<CommandProtocol>)uneCommande apresDelai:(float)unDelai
{
	[(id)uneCommande performSelector:@selector(execute) withObject:nil afterDelay:unDelai];
}

- (void)desactiver:(id<CommandProtocol>)uneCommande
{
	NSTimer* leTimer = [lesTimers objectForKey:[uneCommande getName]];
	[lesTimers removeObjectForKey:[uneCommande getName]];
	[leTimer invalidate];
	[leTimer release];
	leTimer = nil;
}

@end
